package GUItest;

import java.sql.*;

public class ConnectionHandler 
{
	private Connection con;
	private String db;
	private String user;
	private String password;
	
	public ConnectionHandler(String db, String user, String password)
	{
		this.db = db;
		this.user = user;
		this.password = password;
	}
	
	public void establishConnection()
	{	
		try 
		{

			Class.forName("com.mysql.jdbc.Driver");

			String url = "jdbc:mysql://cs341.cs.uwosh.edu:4381/" + db;


			con = DriverManager.getConnection(url, user, password);
			
			System.out.println("URL: " + url);
			System.out.println("Connection: " + con);

		}
		catch( Exception e ) 
		{
			System.err.println("Could not make connection to the database");
			e.printStackTrace();
		}
	}
	
	public void closeConnection()
	{
		try {
			con.close();
		} catch (SQLException e) {
			System.err.println("Could not close database connection");
		}
	}
	
	public Connection getCon()
	{
		return con;
	}

}
